package cn.bcsp.convert;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Description: TODO
 * @author: 颜淮川
 * @date: 2021年07月29日 13:00
 */
public class StringToDataConverter implements Converter<String, Date> {

    private String pattern;

    public StringToDataConverter(String pattern) {
        this.pattern = pattern;
    }

    @Override
    public Date convert(String s) {
        Date date = null;
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
            date = dateFormat.parse(s);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}
